package cn.cvs.entity;

import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;

/**
 * 系统用户类
 * @author project.cvs.team
 */
public class SysUser {
	private Integer id;                //id
	private String account;            //账号
	private String password;            //密码
	private String realName;            //真是姓名
	private Integer roleId;            //角色id
	private String phone;            //电话
	private String address;            //地址
	private Integer sex;                //性别
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@JSONField(format = "yyyy-MM-dd")
	private LocalDate birthday;            //出生日期
	private Integer createdUserId;    //创建人id
	private Date createdTime;        //创建时间
	private Integer updatedUserId;    //修改人id
	private Date updatedTime;        //修改时间
	private String idPicPath;            //证件照路径
	private String workPicPath;        //工作证照片路径

	private Integer age;                //用户年龄
	private String roleIdName;            //角色名称

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public Integer getRoleId() {
		return roleId;
	}

	public void setRoleId(Integer role) {
		this.roleId = role;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public LocalDate getBirthday() {
		return birthday;
	}

	public void setBirthday(LocalDate birthday) {
		this.birthday = birthday;
	}

	public Integer getCreatedUserId() {
		return createdUserId;
	}

	public void setCreatedUserId(Integer createdUserId) {
		this.createdUserId = createdUserId;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Integer getUpdatedUserId() {
		return updatedUserId;
	}

	public void setUpdatedUserId(Integer updatedUserId) {
		this.updatedUserId = updatedUserId;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public Integer getAge() {
		/*long time = System.currentTimeMillis()-birthday.getTime();
		Integer age = Long.valueOf(time/365/24/60/60/1000).IntegerValue();*/
//		Date date = new Date();
//		Integer age = date.getYear() - birthday.getYear();
//		return age;
		if (birthday == null) {
			return null;
		}
		LocalDate now = LocalDate.now();
		return Period.between(birthday, now).getYears();
	}

	public String getRoleIdName() {
		return roleIdName;
	}

	public void setRoleIdName(String roleIdName) {
		this.roleIdName = roleIdName;
	}

	public String getIdPicPath() {
		return idPicPath;
	}

	public void setIdPicPath(String idPicPath) {
		this.idPicPath = idPicPath;
	}

	public String getWorkPicPath() {
		return workPicPath;
	}

	public void setWorkPicPath(String workPicPath) {
		this.workPicPath = workPicPath;
	}

	public int addSysUser(SysUser user) {
		return 0;
	}

    /**
     * 将 LocalDate 类型的生日转换为 java.util.Date 类型
     * @return 转换后的 Date 对象，若 birthday 为 null 则返回 null
     */
    public Date getBirthdayAsDate() {
        if (birthday != null) {
            return Date.from(birthday.atStartOfDay(ZoneId.systemDefault()).toInstant());
        }
        return null;
    }

}

